<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 项目数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\EpisodeAllocationService;
use think\Request;

class EpisodeAllocationController extends VerifyController
{
    /**
     * @var EpisodeAllocationService
     */
    private $episodeAllocationService;

    public function __construct()
    {
        parent::__construct();
        $this->episodeAllocationService = EpisodeAllocationService::getInstance();
    }


    /**
     * 剧集列表
     * @param Request $request
     * @return \think\Response
     */
    public function selectEpisodeWithAllocation(Request $request)
    {
        $param = $request->param();
        $res = $this->episodeAllocationService->selectEpisodeWithAllocation($param);
        return json(success_response('', $res));
    }

    /**
     * 分配剧集
     * @param Request $request
     * @return \think\Response
     */
    public function allocationEpisode(Request $request)
    {
        $param = $request->param();
        $res = $this->episodeAllocationService->allocationEpisode($param['data'], $request->getTenantId());
        return json(success_response('', $res));
    }

    /**
     * 用户项目剧集分配树
     * @param Request $request
     * @return \think\Response
     */
    public function selectProjectEpisodeAllocationTree(Request $request)
    {
        $param = $request->param();
        $res = $this->episodeAllocationService->selectProjectEpisodeAllocationTree($param['param'], $request->getTenantId(), $request->getUserId());
        return json(success_response('', $res));
    }

    /**
     * 查询分配的实体
     * @param Request $request
     * @return \think\Response
     */
    public function selectByUser(Request $request)
    {
        $param = $request->param();
        $res = $this->episodeAllocationService->selectByUser($param['param']['filter'], $request->getTenantId(), $request->getUserId());
        return json(success_response('', $res));
    }

    /**
     * 查询当前用户被分配的剧集
     * @param Request $request
     * @return \think\Response
     */
    public function selectCurrentUserByRoleCode(Request $request)
    {
        $param = $request->param();
        $param['param']['filter']['user_id'] = $request->getUserId();
        $res = $this->episodeAllocationService->selectCurrentUserByRoleCode($param['param']['filter']);
        return json(success_response('', $res));
    }

    /**
     * 根据项目查找剧集进度
     * @param Request $request
     * @return \think\Response
     * @throws \think\Exception
     */
    public function selectEpisodeScheduleByProject(Request $request)
    {
        $param = $request->param();
        $res = $this->episodeAllocationService->selectEpisodeScheduleByProject($param['param'], $request->getTenantId());
        return json(success_response('', $res));
    }

}
